
/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package Apusic.impl;

import Apusic.ApusicPackage;
import Apusic.ThreadPool;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import javax.management.ObjectName;
import org.eclipse.emf.ecore.EObject;
import com.apusic.admin.config.*;
import com.apusic.admin.*;

import cn.edu.pku.sei.ra.wrapping.CommonWrapping.WrappingEObject;
import cn.edu.pku.sei.ra.wrapping.CommonWrapping.impl.WrappingEObjectImpl;
import cn.edu.pku.sei.ra.wrapping.CommonWrapping.util.EObjectContainmentEListForWrapping;
import cn.edu.pku.sei.ra.wrapping.CommonWrapping.util.EObjectResolvingEListForWrapping;
import cn.edu.pku.sei.ra.wrapping.CommonWrapping.util.ImagePool;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Thread Pool</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link Apusic.impl.ThreadPoolImpl#getThreadPoolName <em>Thread Pool Name</em>}</li>
 *   <li>{@link Apusic.impl.ThreadPoolImpl#getStateString <em>State String</em>}</li>
 *   <li>{@link Apusic.impl.ThreadPoolImpl#getIdleTimeout <em>Idle Timeout</em>}</li>
 *   <li>{@link Apusic.impl.ThreadPoolImpl#getMaxQueueSize <em>Max Queue Size</em>}</li>
 *   <li>{@link Apusic.impl.ThreadPoolImpl#getMaxSpareThreads <em>Max Spare Threads</em>}</li>
 *   <li>{@link Apusic.impl.ThreadPoolImpl#getMaxThreads <em>Max Threads</em>}</li>
 *   <li>{@link Apusic.impl.ThreadPoolImpl#getMinSpareThreads <em>Min Spare Threads</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ThreadPoolImpl extends WrappingEObjectImpl implements ThreadPool
{
  /**
   * The default value of the '{@link #getThreadPoolName() <em>Thread Pool Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getThreadPoolName()
   * @generated
   * @ordered
   */
  protected static final String THREAD_POOL_NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getThreadPoolName() <em>Thread Pool Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getThreadPoolName()
   * @generated
   * @ordered
   */
  protected String threadPoolName = THREAD_POOL_NAME_EDEFAULT;

  /**
   * The default value of the '{@link #getStateString() <em>State String</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStateString()
   * @generated
   * @ordered
   */
  protected static final String STATE_STRING_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getStateString() <em>State String</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStateString()
   * @generated
   * @ordered
   */
  protected String stateString = STATE_STRING_EDEFAULT;

  /**
   * The default value of the '{@link #getIdleTimeout() <em>Idle Timeout</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getIdleTimeout()
   * @generated
   * @ordered
   */
  protected static final int IDLE_TIMEOUT_EDEFAULT = 0;

  /**
   * The cached value of the '{@link #getIdleTimeout() <em>Idle Timeout</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getIdleTimeout()
   * @generated
   * @ordered
   */
  protected int idleTimeout = IDLE_TIMEOUT_EDEFAULT;

  /**
   * The default value of the '{@link #getMaxQueueSize() <em>Max Queue Size</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMaxQueueSize()
   * @generated
   * @ordered
   */
  protected static final int MAX_QUEUE_SIZE_EDEFAULT = 0;

  /**
   * The cached value of the '{@link #getMaxQueueSize() <em>Max Queue Size</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMaxQueueSize()
   * @generated
   * @ordered
   */
  protected int maxQueueSize = MAX_QUEUE_SIZE_EDEFAULT;

  /**
   * The default value of the '{@link #getMaxSpareThreads() <em>Max Spare Threads</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMaxSpareThreads()
   * @generated
   * @ordered
   */
  protected static final int MAX_SPARE_THREADS_EDEFAULT = 0;

  /**
   * The cached value of the '{@link #getMaxSpareThreads() <em>Max Spare Threads</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMaxSpareThreads()
   * @generated
   * @ordered
   */
  protected int maxSpareThreads = MAX_SPARE_THREADS_EDEFAULT;

  /**
   * The default value of the '{@link #getMaxThreads() <em>Max Threads</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMaxThreads()
   * @generated
   * @ordered
   */
  protected static final int MAX_THREADS_EDEFAULT = 0;

  /**
   * The cached value of the '{@link #getMaxThreads() <em>Max Threads</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMaxThreads()
   * @generated
   * @ordered
   */
  protected int maxThreads = MAX_THREADS_EDEFAULT;

  /**
   * The default value of the '{@link #getMinSpareThreads() <em>Min Spare Threads</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMinSpareThreads()
   * @generated
   * @ordered
   */
  protected static final int MIN_SPARE_THREADS_EDEFAULT = 0;

  /**
   * The cached value of the '{@link #getMinSpareThreads() <em>Min Spare Threads</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getMinSpareThreads()
   * @generated
   * @ordered
   */
  protected int minSpareThreads = MIN_SPARE_THREADS_EDEFAULT;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ThreadPoolImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return ApusicPackage.Literals.THREAD_POOL;
  }

  
  

  
  
  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */ 
   public boolean isForCore(Object arg0){
   	boolean result=true;
   	if(core==null) return false;
    try{
    if(core!=null && ((ThreadPoolConfig)core).getThreadPoolName().equals(((ThreadPoolConfig)arg0).getThreadPoolName()))
  result=true;
else
  result=false;
    }
    catch(Exception e){
      result=false;
    }
    return result;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */ 
  public List listSubCores(int featureID){
    List result=new ArrayList();
  
    ThreadPoolConfig core=(ThreadPoolConfig)this.getCore();
    if(core==null) 
      return result;
    switch(featureID){
    
  
  
  
  
  
  
  
  }
    return result;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */ 
  public EClass getChildClassMap(Object object){
    ApusicPackage pack=ApusicPackage.eINSTANCE;	
  
  
  
  
  
  
  
  
    return null;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getThreadPoolName()
  {
        Object result=null;
        ThreadPoolConfig core=(ThreadPoolConfig)getCore();
        if(core==null) return threadPoolName;	
        try
{
threadPoolName=core.getThreadPoolName();
}
catch(Exception e)
{
  threadPoolName = null;
}
    return threadPoolName; 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setThreadPoolName(String newThreadPoolName)
  {
    String oldThreadPoolName = threadPoolName;
    threadPoolName = newThreadPoolName;
        	
      ThreadPoolConfig core=(ThreadPoolConfig)getCore();
      if(core==null) return;
      	
        
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ApusicPackage.THREAD_POOL__THREAD_POOL_NAME, oldThreadPoolName, threadPoolName));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getStateString()
  {
        Object result=null;
        ThreadPoolConfig core=(ThreadPoolConfig)getCore();
        if(core==null) return stateString;	
        try
{
stateString=core.getStateString();
}
catch(Exception e)
{
  stateString = null;
}
    return stateString; 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setStateString(String newStateString)
  {
    String oldStateString = stateString;
    stateString = newStateString;
        	
      ThreadPoolConfig core=(ThreadPoolConfig)getCore();
      if(core==null) return;
      	
        
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ApusicPackage.THREAD_POOL__STATE_STRING, oldStateString, stateString));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getIdleTimeout()
  {
        Object result=null;
        ThreadPoolConfig core=(ThreadPoolConfig)getCore();
        if(core==null) return idleTimeout;	
        try
{
idleTimeout=core.getIdleTimeout();
}
catch(Exception e)
{
  idleTimeout = -1;
}
    return idleTimeout; 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setIdleTimeout(int newIdleTimeout)
  {
    int oldIdleTimeout = idleTimeout;
    idleTimeout = newIdleTimeout;
        	
      ThreadPoolConfig core=(ThreadPoolConfig)getCore();
      if(core==null) return;
      	
        try
{
core.setIdleTimeout(idleTimeout);
ThreadPoolManagerImpl parent=(ThreadPoolManagerImpl)((WrappingEObjectImpl)this.eContainer());
((ThreadPoolMgr)(parent.getCore())).updateThreadPool(core);

}
catch(Exception e)
{

}
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ApusicPackage.THREAD_POOL__IDLE_TIMEOUT, oldIdleTimeout, idleTimeout));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getMaxQueueSize()
  {
        Object result=null;
        ThreadPoolConfig core=(ThreadPoolConfig)getCore();
        if(core==null) return maxQueueSize;	
        try
{
maxQueueSize=core.getMaxQueueSize();
}
catch(Exception e)
{
  maxQueueSize = -1;
}
    return maxQueueSize; 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMaxQueueSize(int newMaxQueueSize)
  {
    int oldMaxQueueSize = maxQueueSize;
    maxQueueSize = newMaxQueueSize;
        	
      ThreadPoolConfig core=(ThreadPoolConfig)getCore();
      if(core==null) return;
      	
        try
{
core.setMaxQueueSize(maxQueueSize);
ThreadPoolManagerImpl parent=(ThreadPoolManagerImpl)((WrappingEObjectImpl)this.eContainer());
((ThreadPoolMgr)(parent.getCore())).updateThreadPool(core);

}
catch(Exception e)
{

}
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ApusicPackage.THREAD_POOL__MAX_QUEUE_SIZE, oldMaxQueueSize, maxQueueSize));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getMaxSpareThreads()
  {
        Object result=null;
        ThreadPoolConfig core=(ThreadPoolConfig)getCore();
        if(core==null) return maxSpareThreads;	
        try
{
maxSpareThreads=core.getMaxSpareThreads();
}
catch(Exception e)
{
  maxSpareThreads = -1;
}
    return maxSpareThreads; 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMaxSpareThreads(int newMaxSpareThreads)
  {
    int oldMaxSpareThreads = maxSpareThreads;
    maxSpareThreads = newMaxSpareThreads;
        	
      ThreadPoolConfig core=(ThreadPoolConfig)getCore();
      if(core==null) return;
      	
        try
{
core.setMaxSpareThreads(maxSpareThreads);
ThreadPoolManagerImpl parent=(ThreadPoolManagerImpl)((WrappingEObjectImpl)this.eContainer());
((ThreadPoolMgr)(parent.getCore())).updateThreadPool(core);

}
catch(Exception e)
{

}
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ApusicPackage.THREAD_POOL__MAX_SPARE_THREADS, oldMaxSpareThreads, maxSpareThreads));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getMaxThreads()
  {
        Object result=null;
        ThreadPoolConfig core=(ThreadPoolConfig)getCore();
        if(core==null) return maxThreads;	
        try
{
maxThreads=core.getMaxThreads();
}
catch(Exception e)
{
  maxThreads = -1;
}
    return maxThreads; 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMaxThreads(int newMaxThreads)
  {
    int oldMaxThreads = maxThreads;
    maxThreads = newMaxThreads;
        	
      ThreadPoolConfig core=(ThreadPoolConfig)getCore();
      if(core==null) return;
      	
        try
{
core.setMaxThreads(maxThreads);
ThreadPoolManagerImpl parent=(ThreadPoolManagerImpl)((WrappingEObjectImpl)this.eContainer());
((ThreadPoolMgr)(parent.getCore())).updateThreadPool(core);

}
catch(Exception e)
{

}
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ApusicPackage.THREAD_POOL__MAX_THREADS, oldMaxThreads, maxThreads));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getMinSpareThreads()
  {
        Object result=null;
        ThreadPoolConfig core=(ThreadPoolConfig)getCore();
        if(core==null) return minSpareThreads;	
        try
{
minSpareThreads=core.getMinSpareThreads();
}
catch(Exception e)
{
  minSpareThreads = -1;
}
    return minSpareThreads; 
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setMinSpareThreads(int newMinSpareThreads)
  {
    int oldMinSpareThreads = minSpareThreads;
    minSpareThreads = newMinSpareThreads;
        	
      ThreadPoolConfig core=(ThreadPoolConfig)getCore();
      if(core==null) return;
      	
        try
{
core.setMinSpareThreads(minSpareThreads);
ThreadPoolManagerImpl parent=(ThreadPoolManagerImpl)((WrappingEObjectImpl)this.eContainer());
((ThreadPoolMgr)(parent.getCore())).updateThreadPool(core);

}
catch(Exception e)
{

}
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ApusicPackage.THREAD_POOL__MIN_SPARE_THREADS, oldMinSpareThreads, minSpareThreads));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case ApusicPackage.THREAD_POOL__THREAD_POOL_NAME:
        return getThreadPoolName();
      case ApusicPackage.THREAD_POOL__STATE_STRING:
        return getStateString();
      case ApusicPackage.THREAD_POOL__IDLE_TIMEOUT:
        return new Integer(getIdleTimeout());
      case ApusicPackage.THREAD_POOL__MAX_QUEUE_SIZE:
        return new Integer(getMaxQueueSize());
      case ApusicPackage.THREAD_POOL__MAX_SPARE_THREADS:
        return new Integer(getMaxSpareThreads());
      case ApusicPackage.THREAD_POOL__MAX_THREADS:
        return new Integer(getMaxThreads());
      case ApusicPackage.THREAD_POOL__MIN_SPARE_THREADS:
        return new Integer(getMinSpareThreads());
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case ApusicPackage.THREAD_POOL__THREAD_POOL_NAME:
        setThreadPoolName((String)newValue);
        return;
      case ApusicPackage.THREAD_POOL__STATE_STRING:
        setStateString((String)newValue);
        return;
      case ApusicPackage.THREAD_POOL__IDLE_TIMEOUT:
        setIdleTimeout(((Integer)newValue).intValue());
        return;
      case ApusicPackage.THREAD_POOL__MAX_QUEUE_SIZE:
        setMaxQueueSize(((Integer)newValue).intValue());
        return;
      case ApusicPackage.THREAD_POOL__MAX_SPARE_THREADS:
        setMaxSpareThreads(((Integer)newValue).intValue());
        return;
      case ApusicPackage.THREAD_POOL__MAX_THREADS:
        setMaxThreads(((Integer)newValue).intValue());
        return;
      case ApusicPackage.THREAD_POOL__MIN_SPARE_THREADS:
        setMinSpareThreads(((Integer)newValue).intValue());
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case ApusicPackage.THREAD_POOL__THREAD_POOL_NAME:
        setThreadPoolName(THREAD_POOL_NAME_EDEFAULT);
        return;
      case ApusicPackage.THREAD_POOL__STATE_STRING:
        setStateString(STATE_STRING_EDEFAULT);
        return;
      case ApusicPackage.THREAD_POOL__IDLE_TIMEOUT:
        setIdleTimeout(IDLE_TIMEOUT_EDEFAULT);
        return;
      case ApusicPackage.THREAD_POOL__MAX_QUEUE_SIZE:
        setMaxQueueSize(MAX_QUEUE_SIZE_EDEFAULT);
        return;
      case ApusicPackage.THREAD_POOL__MAX_SPARE_THREADS:
        setMaxSpareThreads(MAX_SPARE_THREADS_EDEFAULT);
        return;
      case ApusicPackage.THREAD_POOL__MAX_THREADS:
        setMaxThreads(MAX_THREADS_EDEFAULT);
        return;
      case ApusicPackage.THREAD_POOL__MIN_SPARE_THREADS:
        setMinSpareThreads(MIN_SPARE_THREADS_EDEFAULT);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case ApusicPackage.THREAD_POOL__THREAD_POOL_NAME:
        return THREAD_POOL_NAME_EDEFAULT == null ? threadPoolName != null : !THREAD_POOL_NAME_EDEFAULT.equals(threadPoolName);
      case ApusicPackage.THREAD_POOL__STATE_STRING:
        return STATE_STRING_EDEFAULT == null ? stateString != null : !STATE_STRING_EDEFAULT.equals(stateString);
      case ApusicPackage.THREAD_POOL__IDLE_TIMEOUT:
        return idleTimeout != IDLE_TIMEOUT_EDEFAULT;
      case ApusicPackage.THREAD_POOL__MAX_QUEUE_SIZE:
        return maxQueueSize != MAX_QUEUE_SIZE_EDEFAULT;
      case ApusicPackage.THREAD_POOL__MAX_SPARE_THREADS:
        return maxSpareThreads != MAX_SPARE_THREADS_EDEFAULT;
      case ApusicPackage.THREAD_POOL__MAX_THREADS:
        return maxThreads != MAX_THREADS_EDEFAULT;
      case ApusicPackage.THREAD_POOL__MIN_SPARE_THREADS:
        return minSpareThreads != MIN_SPARE_THREADS_EDEFAULT;
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (threadPoolName: ");
    result.append(threadPoolName);
    result.append(", stateString: ");
    result.append(stateString);
    result.append(", idleTimeout: ");
    result.append(idleTimeout);
    result.append(", maxQueueSize: ");
    result.append(maxQueueSize);
    result.append(", maxSpareThreads: ");
    result.append(maxSpareThreads);
    result.append(", maxThreads: ");
    result.append(maxThreads);
    result.append(", minSpareThreads: ");
    result.append(minSpareThreads);
    result.append(')');
    return result.toString();
  }

} //ThreadPoolImpl
